﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace QaaSimulation.QSim
{
    class QEngine : QModule
    {
        protected float m_Acceleration;
        public float Acceleration
        {
            get
            {
                return m_Acceleration;
            }
            set
            {
                m_Acceleration = value;
            }
        }

        protected float m_BackwardAcceleration;
        public float BackwardAcceleration
        {
            get
            {
                return m_BackwardAcceleration;
            }
            set
            {
                m_BackwardAcceleration = value;
            }
        }

        protected float m_ForwardAcceleration;
        public float ForwardAcceleration
        {
            get
            {
                return m_ForwardAcceleration;
            }
            set
            {
                m_ForwardAcceleration = value;
            }
        }

        protected float m_ActualSpeed;
        public float ActualSpeed
        {
            get
            {
                return m_ActualSpeed;
            }
            set
            {
                m_ActualSpeed = value;
                if (m_ActualSpeed > m_MaximumSpeedForward)
                    m_ActualSpeed = m_MaximumSpeedForward;

                if (m_ActualSpeed < m_MaximumSpeedBackward)
                    m_ActualSpeed = m_MaximumSpeedBackward;
            }
        }

        protected float m_MaximumSpeedForward;
        public float MaximumSpeedForward
        {
            get
            {
                return m_MaximumSpeedForward;
            }
            set
            {
                m_MaximumSpeedForward = value;
            }
        }

        protected float m_MaximumSpeedBackward;
        public float MaximumSpeedBackward
        {
            get
            {
                return m_MaximumSpeedBackward;
            }
            set
            {
                m_MaximumSpeedBackward = value;
            }
        }

        protected void UpdateSpeed(float eTime)
        {
            ActualSpeed += m_Acceleration * eTime;
        }

        public override void Compute(float elapsedTime)
        {
            UpdateSpeed(elapsedTime);
        }

        public PointF CalculateNewMovement(PointF oldMovementSpeed, PointF direction, float elapsedTime)
        {
            PointF newPoint = oldMovementSpeed;
            newPoint.X += direction.X * m_Acceleration * elapsedTime;
            newPoint.Y += direction.Y * m_Acceleration * elapsedTime;
            return newPoint;
        }


    }
}
